#pragma once

#include "comm/my_defs.h"
#include "comm/my_crc.h"
#include "comm/my_fnv_hash.h"

typedef struct my_cache_key_s my_cache_key_t;

struct my_cache_key_s {
    const char          *key;
    int64_t             key_len;
    // find index_item from the volume index table.
    uint64_t            digest;
    // digest64 to digest32
    uint32_t            digest32;
    // foind volume from the consistent hash table.
    uint32_t            crc32;
};

static inline void
my_cache_key_init(my_cache_key_t *cache_key, const char *key, int64_t key_len) {
    cache_key->key = key;
    cache_key->key_len = key_len;
    my_fnv64_init(cache_key->digest);
    my_fnv64_update(&cache_key->digest, key, key_len);
    cache_key->crc32 = my_crc32_long(key, key_len);

    if (cache_key->digest == 0) {
        cache_key->digest = 1;
    }
    
    cache_key->digest32 = (uint32_t)cache_key->digest;
    if (cache_key->digest32 == 0) {
        cache_key->digest32 = 1;
    }
}